package com.weaver.drools.business.sys.user.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.weaver.drools.business.sys.user.service.IUUsrUser36Service;
import com.weaver.drools.common.controller.CommonController;
import com.weaver.drools.common.entity.UUsrUser36;
import com.weaver.drools.common.utils.ControllerUtil;
import com.weaver.drools.common.utils.PageTag;
import com.weaver.drools.common.utils.ReturnMessage;
/**
 * 
 *  @application name: 
 *  @author: zhouxinlei 
 *  @time：2018年6月27日
 *  @version：ver 1.1
 */
@Controller
public class UserController extends CommonController{
	
	@Resource
	private IUUsrUser36Service user36Service;
	/**
	 * 分页查询用户
	 * @param response
	 * @param request
	 * @param pageable
	 * @return
	 * @throws Exception
	 */
	
	@RequestMapping(value ="/queryUserInfoList")
	public String queryUserInfoList(HttpServletResponse response, HttpServletRequest request) throws Exception {
		int pageNum = 0;
		String currentNum = request.getParameter("currentNum");
		String showname = request.getParameter("showname");
		String sexid = request.getParameter("sexid");
		if (currentNum!=null&&!"".equals(currentNum)) {
			pageNum=Integer.valueOf(currentNum);
		}
		PageTag<UUsrUser36> page = user36Service.findUUsrUser36List(pageNum, showname, Long.valueOf(sexid));
		request.setAttribute("UUsrUser36List", page.getResult());
		request.setAttribute("pageTag", page);
		return "sys/user/userList";
	}
	@RequestMapping(value ="/userInfoSearch",method = RequestMethod.GET)
	public String UserInfoSearch(HttpServletResponse response, HttpServletRequest request) throws Exception {
		return "sys/user/userSearch";
		
	}
	/**
	 * 查看用户信息
	 * @param response
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value ="/viewUserInfo")
	public String viewUserInfo(HttpServletResponse response, HttpServletRequest request) throws Exception {
		String userid= request.getParameter("userId");
		String currentUserId= request.getParameter("currentUserId");
		UUsrUser36 user36 =null;
		if(currentUserId!=null&&!currentUserId.equals("")&&currentUserId.equals("0")) {
			user36=this.getSessionUserBean();
		}else {
			user36=user36Service.findById(Long.valueOf(userid));
		}
		request.setAttribute("user", user36);
		return "sys/user/userView";
		
	}
	/**
	 * 更新用户转发
	 * @param response
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value ="/updataUserForworrd")
	public String updataUserForworrd(HttpServletResponse response, HttpServletRequest request) throws Exception {
		String userid= request.getParameter("userId");
		String currentUserId= request.getParameter("currentUserId");
		UUsrUser36 user36 =null;
		if(currentUserId!=null&&!currentUserId.equals("")&&currentUserId.equals("0")) {
			user36=this.getSessionUserBean();
		}else {
			user36=user36Service.findById(Long.valueOf(userid));
		}
		request.setAttribute("user", user36);
		return "sys/user/userUpdate";
		
	}
	/**
	 * 新增用户转发
	 * @param response
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value ="/addUserForworrd")
	public String addUserForworrd(HttpServletResponse response, HttpServletRequest request) throws Exception {
		return "sys/user/userAdd";
	}
	/**
	 * 删除用户
	 * @param response
	 * @param request
	 * @throws Exception
	 */
	@RequestMapping(value ="/deleteUser")
	@ResponseBody
	public void deleteUser(HttpServletResponse response, HttpServletRequest request) throws Exception {
		String userId= request.getParameter("userId");
		String cs = "";
		try {
			user36Service.deleteUUsrUser36(Long.valueOf(userId));
			cs = ReturnMessage.messageData(ReturnMessage.SUCCESS, "删除用户成功！",null);
		} catch (Exception e) {
			e.printStackTrace();
			cs = ReturnMessage.messageData(ReturnMessage.FAIL, "删除用户失败！",null);
		}
		ControllerUtil.writejsonAndSession(response,request,cs);
	}
}
